package com.bootdo.lvyou_specialty.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.Document;

import com.bootdo.common.utils.DocumentUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.bootdo.common.controller.BaseController;
import com.bootdo.lvyou_specialty.domain.LvyouSpecialtyProductArticle;
import com.bootdo.lvyou_specialty.service.LvyouSpecialtyProductArticleService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author haojiangbo
 * @email 2100272728@qq.com
 * @date 2019-10-10 11:41:31
 */
 
@Controller
@RequestMapping("/lvyou_specialty/lvyouSpecialtyProductArticle")
public class LvyouSpecialtyProductArticleController extends BaseController{


	@Autowired
	private LvyouSpecialtyProductArticleService lvyouSpecialtyProductArticleService;
	
	@ModelAttribute
	public LvyouSpecialtyProductArticle get(@RequestParam(required=false) Long id) {
		if (id != null){
			return lvyouSpecialtyProductArticleService.get(id);
		}else{
			return new LvyouSpecialtyProductArticle();
		}
	}


	
	//insert into sys_menu(parent_id,name,url,perms,type)  values (149,'测试','/lvyou_specialty/lvyouSpecialtyProductArticle','lvyou_specialty:lvyouSpecialtyProductArticle:lvyouSpecialtyProductArticle',1)
	//insert into sys_menu(parent_id,name,url,perms,type)  values (160,'修改','','lvyou_specialty:lvyouSpecialtyProductArticle:edit',2)
	//type 0是分类菜单 1是小菜但 2是按钮
	@GetMapping()
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:lvyouSpecialtyProductArticle")	
	String LvyouSpecialtyProductArticle(LvyouSpecialtyProductArticle lvyouSpecialtyProductArticle,HttpServletRequest request,HttpServletResponse response){
	    return "lvyou_specialty/lvyouSpecialtyProductArticle/lvyouSpecialtyProductArticle";
	}
	
	@ResponseBody
	@PostMapping("/list")
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:lvyouSpecialtyProductArticle")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<LvyouSpecialtyProductArticle> lvyouSpecialtyProductArticleList = lvyouSpecialtyProductArticleService.list(query);
		int total = lvyouSpecialtyProductArticleService.count(query);
		PageUtils pageUtils = new PageUtils(lvyouSpecialtyProductArticleList, total);
		return R.ok().put("rows", lvyouSpecialtyProductArticleList).put("total", total);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:edit")
	String add(LvyouSpecialtyProductArticle lvyouSpecialtyProductArticle,HttpServletRequest request,HttpServletResponse response){
	    return "lvyou_specialty/lvyouSpecialtyProductArticle/lvyouSpecialtyProductArticleedit";
	}

	@PostMapping("/getById")
	@ResponseBody
	R getById(LvyouSpecialtyProductArticle lvyouSpecialtyProductArticle) {
		return R.ok().put("i",lvyouSpecialtyProductArticle);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:edit")
	public R save( LvyouSpecialtyProductArticle lvyouSpecialtyProductArticle){

		lvyouSpecialtyProductArticle.setContext(DocumentUtil.setWidth(lvyouSpecialtyProductArticle.getContext()));
		if(lvyouSpecialtyProductArticleService.save(lvyouSpecialtyProductArticle)>0){
			return R.ok();
		}
		return R.error();
	}
	
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:edit")
	public R remove( Long id){
		if(lvyouSpecialtyProductArticleService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("lvyou_specialty:lvyouSpecialtyProductArticle:edit")
	public R remove(@RequestParam("ids[]") Long[] ids){
		lvyouSpecialtyProductArticleService.batchRemove(ids);
		return R.ok();
	}
	
}